from PyQt5.QtWidgets import *
from PyQt5 import QtGui
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import time
import pymysql

import database.admin.setting as setting
import interface.student.to_be_comment as to_be_comment
import interface.student.course_comment_Window as course_comment_Window
class to_be_comment_window(QMainWindow,to_be_comment.Ui_Form):###点击用户身份弹出的登陆小弹窗
    def __init__(self,sid):
        QMainWindow.__init__(self)
        to_be_comment.Ui_Form.__init__(self)
        self.sid=sid
        self.setupUi(self)
        self.table.setColumnCount(5)
        self.table.setHorizontalHeaderLabels(['课程号', '课程名', '授课教师','选课学期', '评价'])
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Interactive)
        self.table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
        self.setWindowTitle("评教")
        self.quit.clicked.connect(self.close)
        self.init_table()
    def init_table(self):
        self.connect = pymysql.connect(**setting.config)
        self.cursor = self.connect.cursor()
        sql_="select name,school from students where id=%s"
        self.cursor.execute(sql_,self.sid)
        r=self.cursor.fetchone()
        self.name_l.setText(r[0])
        self.school_l.setText(r[1])
        self.id_l.setText(self.sid)
        sql_="select  s.cid,c.cname,c.tname,s.time  from select_course_state s,course c where s.sid=%s and s.status=1 and s.cid=c.id and  \
                     s.cid not in (select cid from course_comment where sid=%s)"
        self.cursor.execute(sql_,(self.sid,self.sid))
        re=self.cursor.fetchall()
        self.display_find_result(re)
    def sel_but(self, cid, sid):
        widget = QWidget()
        sel = QPushButton("评价")
        q = course_comment_Window.course_comment_window(cid, sid)
        def load_():
            # QMessageBox.about(self, "提示", "是否选课")
            q.show()
        sel.clicked.connect(load_)
        return sel
    def display_find_result(self, re):
        self.table.setRowCount(0)
        row = self.table.rowCount()
        re_len = len(re)
        # print(re[2])
        for l in range(re_len):
            # print(l)
            row = self.table.rowCount()
            self.table.setRowCount(row + 1)

            check = QtWidgets.QTableWidgetItem()
            check.setCheckState(QtCore.Qt.Unchecked)
            # self.table.setHorizontalHeaderLabels('课程好', '课程名', '授课教师', '评价']])
            # print(type(re))
            self.table.setItem(row, 0, QTableWidgetItem(re[l][0]))
            self.table.setItem(row, 1, QTableWidgetItem(re[l][1]))
            self.table.setItem(row, 2, QTableWidgetItem(re[l][2]))
            self.table.setItem(row, 3, QTableWidgetItem(re[l][3]))
            sel = self.sel_but(re[l][0], self.sid)
            self.table.setCellWidget(row, 4, sel)
            # self.table.setCellWidget(row, 5,w)
if __name__=='__main__':
    app=QApplication(sys.argv)
    md=to_be_comment_window("2018300354")
    md.show()
    sys.exit(app.exec_())